<?php


class company 
{
	public $company_active = 0;
	public $arname = '';
	public $enname = '';
	public $email = '';

	
	function __construct($arname,$enname,$email)
	{
		
		$this->arname = sanitize($arname);
		$this->enname = sanitize($enname);
		$this->email = sanitize($email);
		
		/*
		else if(coemailExists($this->clean_email))
		{
			$this->email_taken = true;
		}
		else
		{
			//No problems have been found.
			$this->status = true;
		}
		*/
	}
	
	public function AddCompany()
	{
		global $db,$emailActivation,$websiteUrl,$db_table_prefix,$mailer,$smarty,$server;
	
			
					//Insert the user into the database providing no errors have been found.
					if (!emailExists($this->email)){
					$sql = "INSERT INTO ".$db_table_prefix."companies (
							ArName,
							EnName,
							Active
							)
					 		VALUES (
							'".$db->sql_escape($this->arname)."',
							'".$db->sql_escape($this->enname)."',
							'0'
							)";
						//die($sql);
					$db->sql_query($sql);
							generateActivationToken();
							$cid=getlastinsertid();
							//$cid[comid] =$cid[comid] + 1;
							//echo $cid[comid];
							$activation_token=generateActivationToken();
							AddUser($this->email,$this->email,$activation_token,2,$cid[comid]);	
														}
							else
							{
							return false;
			
			}
			
			//send email
			$Subject="CMA CEO Activation";
			$From=array('ammar@edutech.com' => 'Capital Markets Authority');
			//$To=array('ammar@edutech.com' => 'ammar','mohammadn@edutech.com' => 'mohammadn');
			$To=array($this->email, 'ammar@edutech.com' => 'ammar','mohammadn@edutech.com' => 'mohammadn');
			$smarty->assign('token',$activation_token);
			$smarty->assign('server',$server);
			$EmailBody=$smarty->fetch('tpls/email/ceo_email.tpl');;
			//$EmailBodyAlter='Here is the message itself';

			//construct email
			$message = Swift_Message::newInstance($Subject)
			  ->setFrom($From)
			  ->setTo($To)
			  ->setBody($EmailBody,'text/html');
			 //Add Attachment
			 // $message->attach(Swift_Attachment::fromPath('/path/to/image.jpg'));
			   
			// Send the message $result must have a value indicates count of successfull sent mails
			$result = $mailer->send($message);
			/*if ($result)
			{
			echo "Email Sent succesfully";
			}else
			{
			echo "failed";
			}*/					
							
				return true;
		/*}*/	
	}
}


?>